home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / video / zapem-0.000 / zapem-0 / zapem / RawKey.cc < prev    next >
C/C++ Source or Header  |  1995-06-06  |  2KB  |  98 lines

  1. /*    Copyright Alex Hornby 1994/1995. All rights reserved.
  2.      See file README for details
  3. */
  4.  
  5. /*    Make use of the svgalib raw keyboard mode. Somewhat risky as it can
  6.     freeze the console!
  7. */
  8.  
  9. #include <iostream.h>
  10. #include <vga.h>
  11. #include <vgakeyboard.h>
  12. #include "RawKey.h"
  13.  
  14. RawKey::RawKey() : Control()
  15. {
  16.     //calibrate();
  17.     int status=keyboard_init();
  18.     if(status!=0) 
  19.     {
  20.         cerr << "keyboard_init failed" << endl;
  21.         raw=false;
  22.         okay=false;
  23.     }
  24.     else
  25.     {
  26.         raw=true;
  27.         okay=true;
  28.     }
  29.     left=SCANCODE_CURSORBLOCKLEFT; right=SCANCODE_CURSORBLOCKRIGHT;
  30.     up=SCANCODE_CURSORBLOCKUP; down=SCANCODE_CURSORBLOCKDOWN;
  31.     fire1=SCANCODE_LEFTCONTROL; quit=SCANCODE_ESCAPE; pause=25;
  32.     fire2=SCANCODE_LEFTALT; fire3=SCANCODE_SPACE; fire4=42;
  33. }
  34.  
  35. RawKey::~RawKey()
  36. {
  37.     if(raw==true)
  38.         keyboard_close();
  39. }
  40.  
  41. int
  42. RawKey::getkey(void)
  43. {
  44.     int k=-1,j=25;
  45.     while(k==-1)
  46.         k=vga_getkey();
  47.     while(j!=-1)
  48.         j=vga_getkey();
  49.     return k;
  50. }
  51.  
  52. void
  53. RawKey::calibrate(void)
  54. {
  55.     cout << "Press key for LEFT\n";
  56.     left=getkey();
  57.     cout << "Press key for RIGHT\n";
  58.     right=getkey();
  59.     cout << "Press key for UP\n";
  60.     up=getkey();
  61.     cout << "Press key for DOWN\n";
  62.     down=getkey();
  63.     cout << "Press key for FIRE1\n";
  64.     fire1=getkey();
  65.     cout << "Press key for FIRE2\n";
  66.     fire2=getkey();
  67. }
  68.  
  69. void
  70. RawKey::fetch(void)
  71. {
  72.     keyboard_update();
  73.     for(int i=0;i<=FIRE4;i++)
  74.         last[i]=false;
  75.     if(keyboard_keypressed(right))
  76.         last[RIGHT]=true;
  77.     else if(keyboard_keypressed(left))
  78.         last[LEFT]=true;
  79.     if(keyboard_keypressed(down))
  80.         last[DOWN]=true;
  81.     else if(keyboard_keypressed(up))
  82.         last[UP]=true;
  83.     if(keyboard_keypressed(fire1)) 
  84.         last[FIRE1]=true;
  85.     if(keyboard_keypressed(fire2)) 
  86.         last[FIRE2]=true;
  87.     if(keyboard_keypressed(fire3)) 
  88.         last[FIRE3]=true;
  89.     if(keyboard_keypressed(fire4)) 
  90.         last[FIRE4]=true;
  91.     if(keyboard_keypressed(quit)) 
  92.         last[QUIT]=true;
  93.     if(keyboard_keypressed(pause)) 
  94.         last[PAUSE]=true;
  95.     last[STRAIGHT] = !(last[LEFT] || last[RIGHT] || last[UP] || last[DOWN]);    
  96. }
  97.  
  98.